function [bits_count, probabilities] = adaptive_cost_D(x, alphabet_size)
    [bits_count, probabilities] = adaptive_cost(x, alphabet_size, @count_probability_D);
end

function [p] = count_probability_D(num, t, current_alphabet_size, alphabet_size)
	if (num == 0)
		if (t == 0)
			p = 1 / alphabet_size;
		else
               		p = current_alphabet_size / 2 / t / (alphabet_size - current_alphabet_size);
		end;
	else 
		if (current_alphabet_size == alphabet_size)
        		p = num / t; 
		else
			p = (num - 0.5) / (t + 1); 
		end;
	end;
end
